home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util3 / dops1541.lha / DOpus-1541 / REXX / DOPUS / 1541 / 1541Copy.rexx < prev    next >
OS/2 REXX Batch file  |  1995-02-24  |  5KB  |  215 lines

  1. /*
  2.  *
  3.  * Copy file(s) between 1541 and Amiga
  4.  *
  5.  * (c) 1995 by Christer Bjarnemo  mr.bjarnemo@mn.medstroms.se
  6.  *
  7.  * Based on Twin-Dopus by Patrick Van Beem (patrick.van.beem@aobh.xs4all.nl),
  8.  * which based he's script on the DOpusLhaARexx package by Geoff Seeley.
  9.  *
  10.  */
  11.  
  12. dircmd = "Work:Emulators/A64/Utils/"    /* Note. If the file ENVARC:1541.PREFS */
  13. rxdir =  "Rexx:Dopus/1541/"             /* exists, that one will override the  */
  14. tmpdir = "t:"                           /* settings here...                    */
  15. DOpusPort   = 'DOPUS.1'
  16.  
  17. snuff = '22'x
  18.  
  19. if open(1,'env:1541.prefs','Read') then do
  20.         dircmd = readln(1)
  21.     rxdir  = readln(1)
  22.         tmpdir = readln(1)
  23.         end
  24. close(1)
  25.  
  26. dircmd = slashpath(dircmd)
  27. rxdir =  slashpath(rxdir)
  28. tmpdir = slashpath(tmpdir)
  29.  
  30. if ~show(l,"rexxsupport.library") then        
  31.     call addlib("rexxsupport.library",0,-30,0)
  32. if showlist('Ports', DOpusPort) = 0 then do
  33.    say 'Directory Opus Arexx port not found. Aborting.'
  34.    call CleanUp
  35. end
  36.  
  37. address(DOpusPort)
  38. options results
  39.  
  40. /* setup DOpus window and tell user what's happening */
  41. Busy on
  42. TopText "Copying selected files..."
  43.  
  44. /* Get the destination path */
  45. OtherWindow
  46. 'Status 6 -1'
  47. GetEntry Result
  48. ToPath = Result
  49. if left(ToPath,1) = '*' then do
  50.    ToPath = SubStr(ToPath,2)
  51.    DoReread='TRUE'
  52. end
  53. else do
  54.    'Status 13 -1'
  55.    ToPath = result
  56.    if ToPath = '' then do
  57.       TopText "No destination directory selected."
  58.       call CleanUp
  59.    end
  60.    DoReread='FALSE'
  61. end
  62. ToPath=Quote(ToPath)
  63. OtherWindow
  64.  
  65.  
  66. /* Get the current path and do file-copy, depending on the  */
  67. /* type of path (1541/normal path)                          */
  68. 'Status 6 -1'
  69. GetEntry Result
  70. FilePath = Result
  71.  
  72. /* 1541-way */
  73. if left(FilePath,1) = '*' then do
  74.    FilePath = SubStr(FilePath,2)
  75.    GetSelectedAll
  76.    SelectedEntries = result
  77.    if SelectedEntries = 'RESULT' then do
  78.       TopText "No files selected."
  79.       call CleanUp
  80.    end
  81.    NumberOfEntries = words(SelectedEntries)
  82.    do EntryNumber = 1 to NumberOfEntries
  83.       Index = word(SelectedEntries, EntryNumber)
  84.       GetEntry Index+1
  85.       Entry = result
  86.       File = strip(left(Entry,25))
  87.  
  88.     toptext 'Copying "'File'" to 'ToPath'...'
  89.  
  90.       if right(FilePath,1) = ':' then
  91.          File = Quote(FilePath || File)
  92.       else
  93.          File = Quote(FilePath || '' || File)
  94.       address command dircmd'64toAmiga >'tmpdir'1541.tmp 'File' 'left(ToPath,length(ToPath)-1)''right(File,length(File)-1)' 8'
  95.  
  96. if open(1,tmpdir'1541.tmp','Read') then do
  97.         Do for 8 ; tmp = readln(1) ; End
  98.     say tmp
  99.     Toptext tmp
  100.         close(1)
  101.         end
  102.  
  103.       selection = Index||' 0 0'
  104.       SelectEntry selection
  105.    end
  106. end
  107.  
  108. /* Normal way */
  109. else do
  110.    'Status 13 -1'
  111.    FilePath = result
  112.    if FilePath = '' then do
  113.       TopText "No source directory selected."
  114.       call CleanUp
  115.    end
  116.    'GetSelectedAll "|" -1'
  117.    SelectedEntries = result
  118.    if SelectedEntries = 'RESULT' then do
  119.       TopText "No files selected."
  120.       call CleanUp
  121.    end
  122.    NumberOfEntries = CountWords(SelectedEntries)
  123.    do EntryNumber = 1 to NumberOfEntries
  124.       File = GetWord(EntryNumber, SelectedEntries)
  125.  
  126.     toptext 'Writing "'File'" to 1541...'
  127.  
  128.       SelectFile Quote(File)
  129.       FileOnly = Quote(File)
  130.       File = Quote(FilePath || File)
  131.     address command dircmd'Amigato64 >'tmpdir'1541.tmp 'left(ToPath,length(ToPath)-1)''right(File,length(File)-1)' 'FileOnly' 8'
  132.  
  133. if open(1,tmpdir'1541.tmp','Read') then do
  134.         Do for 9 ; tmp = readln(1) ; End
  135.     say tmp
  136.     Toptext tmp
  137.         close(1)
  138.         end
  139.  
  140.    end
  141. end
  142.  
  143. 'DisplayDir -1'
  144.  
  145. if DoReread='TRUE' then do
  146.    otherwindow
  147.    say rxdir
  148.    address arexx rxdir'1541Dir.rexx'
  149. end
  150. else do
  151.     otherwindow
  152.     'rescan -1'
  153.     otherwindow
  154.     end
  155.  
  156. call CleanUp
  157.  
  158. exit
  159.  
  160. /*---------------------------------------------------------------------------*/
  161.  
  162. CleanUp: /* Remove any files and exit */
  163.    Busy off
  164.    exit
  165. return
  166.  
  167. /*--------------------------------------------------------------------------*/
  168.  
  169. Quote: procedure /* add quotes to string */
  170.    parse arg string
  171. return '"'||string||'"'
  172.  
  173. /*--------------------------------------------------------------------------*/
  174.  
  175. GetWord: procedure /* get word from '|' separated string */
  176.  
  177.   parse arg number,words
  178.  
  179.   if(left(words,1) ~= '|') then
  180.      words = '|'||words
  181.   do i=1 to number
  182.      idx = index(words, '|');
  183.      words = substr(words, idx+1)
  184.   end
  185.   end = index(words, '|') - 1
  186.   if words = "" then
  187.      return ""
  188.  
  189.   ret_str = substr(words, 1, end)
  190. return ret_str
  191.  
  192. /*--------------------------------------------------------------------------*/
  193.  
  194. CountWords: procedure /* count words from '|' separated string */
  195.  
  196.    parse arg words
  197.  
  198.    count = 0
  199.    idx = index(words, '|')
  200.    do while idx ~= 0
  201.      count = count + 1
  202.      words = substr(words, idx+1)
  203.      idx = index(words, '|')
  204.    end
  205. return count
  206.  
  207. /*---------------------------------------------------------------------------*/
  208. Slashpath: procedure /* Put a (/) or (:) at the end of filenames (if neccessary) */
  209. parse arg string
  210.     if right(string,1) ~= ':' & right(string,1) ~= '/'  then do
  211.         string = string'/'
  212.         end
  213. return string
  214.  
  215.